package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
)



func main() {
	r := gin.Default()
	r.GET("/json",func(c *gin.Context){
		//1.1.方法一：map
		//data:=map[string]interface{}{
		//	"name":"小王子",
		//	"message":"hello world!!!",
		//	"age":18,
		//}
		//1.2.方法二：其实就是type H map[string]interface{}
		data:=gin.H{
			"name":"小王子",
			"message":"hello world!!!",
			"age":20,
		}
		c.JSON(http.StatusOK,data)
	})

	r.GET("/struct_json",func(c *gin.Context){
		//2.1.结构体，灵活使用tag来对结构体做定制化操作
		type msg struct {
			//变量名首字母必须大写
			Name string `json:"name"`
			Message string `json:"message"`
			Age int `json:"age"`
		}
		data:=msg{
			Name:"zhaojinding",
			Message:"hello world!",
			Age:20,
		}
		c.JSON(http.StatusOK,data) //json的序列化，
	})

	r.Run(":9090")
}
